package com.ruoyi.property.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.property.domain.EquallySharedFormula;
import com.ruoyi.property.service.IEquallySharedFormulaService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公摊公式Controller
 * 
 * @author sux
 * @date 2021-06-29
 */
@Controller
@RequestMapping("/property/equallySharedFormula")
public class EquallySharedFormulaController extends BaseController
{
    private String prefix = "property/equallySharedFormula";

    @Autowired
    private IEquallySharedFormulaService equallySharedFormulaService;

    @RequiresPermissions("property:equallySharedFormula:view")
    @GetMapping()
    public String equallySharedFormula()
    {
        return prefix + "/equallySharedFormula";
    }

    /**
     * 查询公摊公式列表
     */
    @RequiresPermissions("property:equallySharedFormula:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EquallySharedFormula equallySharedFormula)
    {
        startPage();
        List<EquallySharedFormula> list = equallySharedFormulaService.selectEquallySharedFormulaList(equallySharedFormula);
        return getDataTable(list);
    }

    /**
     * 导出公摊公式列表
     */
    @RequiresPermissions("property:equallySharedFormula:export")
    @Log(title = "公摊公式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EquallySharedFormula equallySharedFormula)
    {
        List<EquallySharedFormula> list = equallySharedFormulaService.selectEquallySharedFormulaList(equallySharedFormula);
        ExcelUtil<EquallySharedFormula> util = new ExcelUtil<EquallySharedFormula>(EquallySharedFormula.class);
        return util.exportExcel(list, "equallySharedFormula");
    }

    /**
     * 新增公摊公式
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公摊公式
     */
    @RequiresPermissions("property:equallySharedFormula:add")
    @Log(title = "公摊公式", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EquallySharedFormula equallySharedFormula)
    {
        return toAjax(equallySharedFormulaService.insertEquallySharedFormula(equallySharedFormula));
    }

    /**
     * 修改公摊公式
     */
    @GetMapping("/edit/{formulaId}")
    public String edit(@PathVariable("formulaId") Integer formulaId, ModelMap mmap)
    {
        EquallySharedFormula equallySharedFormula = equallySharedFormulaService.selectEquallySharedFormulaById(formulaId);
        mmap.put("equallySharedFormula", equallySharedFormula);
        return prefix + "/edit";
    }

    /**
     * 修改保存公摊公式
     */
    @RequiresPermissions("property:equallySharedFormula:edit")
    @Log(title = "公摊公式", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EquallySharedFormula equallySharedFormula)
    {
        return toAjax(equallySharedFormulaService.updateEquallySharedFormula(equallySharedFormula));
    }

    /**
     * 删除公摊公式
     */
    @RequiresPermissions("property:equallySharedFormula:remove")
    @Log(title = "公摊公式", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(equallySharedFormulaService.deleteEquallySharedFormulaByIds(ids));
    }
}
